#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& nums) {
        int n = nums.size();
        unordered_map<long long, vector<int>> hashi;
        hashi[nums[0]].push_back(0);
        vector<vector<int>> dp(n, vector<int>(n));
        int ret = 0;
        for (int i = 1; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                long long d = (long long)nums[j] - nums[i];
                long long a = nums[i] - d;
                if (hashi.count(a)) {
                    for (auto e : hashi[a]) {
                        dp[i][j] += dp[e][i] + 1;

                    }
                    ret += dp[i][j];
                }
            }
            hashi[nums[i]].push_back(i);
        }
        return ret;
    }
};